﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IronCow.UnitTests.Mock
{
    class MockGroupResponsePart : MockResponsePart
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public List<string> ContactIds { get; private set; }

        public MockGroupResponsePart()
        {
            ContactIds = new List<string>();
        }

		public MockGroupResponsePart(int id, string name)
            : this()
        {
            Id = id.ToString();
            Name = name;
        }

		public MockGroupResponsePart(int id, string name, params int[] contactIds)
            : this(id, name)
        {
			foreach (var contactId in contactIds)
			{
				ContactIds.Add(contactId.ToString());
			}
        }

        public override void GetResponseMarkup(System.Xml.XmlWriter markupWriter, Dictionary<string, string> parameters)
        {
            markupWriter.WriteStartElement("group");
            {
                markupWriter.WriteAttributeString("id", Id);
                markupWriter.WriteAttributeString("name", Name);
                markupWriter.WriteStartElement("contacts");
                {
                    foreach (var id in ContactIds)
                    {
                        markupWriter.WriteStartElement("contact");
                        markupWriter.WriteAttributeString("id", id);
                        markupWriter.WriteEndElement();
                    }
                }
                markupWriter.WriteEndElement();
            }
            markupWriter.WriteEndElement();
        }
    }
}
